registerController.$inject = ['$scope','$location','loginRegisterService'];

var appContext = require('../../../config/app.context');

function registerController($scope, $location, loginRegisterService) {
    
    $scope.doRegister = function($event) {
        console.log(JSON.stringify($scope.regInfo));
        if ($scope.regInfo.cpwd != $scope.regInfo.cpwdCfm) {
            alert('password confirm is invalid!');
            return;
        }
        delete $scope.regInfo.cpwdCfm;
        $scope.regInfo.phone = [{name: $scope.regInfo.phone}];
        loginRegisterService.doRegister($scope.regInfo).then(
            function(response) {
                if (response.data.result) {
                    alert('Register success!');
                    $location.path(appContext.path + '/login');
                } else {
                    console.log(response.data.errMsg);
                }
            },
            function(err) {
                console.log(err.data);
            }
        );
    }
}
module.exports = registerController;